/*class MyCircularQueue {
    private int[] elem;
    int front = 0;
    int rear = 0;
    int usedSize = 0;
    public MyCircularQueue(int k) {
        elem = new int[k];
    }

    public boolean enQueue(int value) {
        if(usedSize != elem.length) {
            elem[rear%elem.length] = value;
            rear++;
            usedSize++;
            return true;
        }
        return false;
    }

    public boolean deQueue() {
        if(usedSize != 0) {
            front = (front + 1) % elem.length;
            usedSize--;
            return true;
        }
        return false;
    }

    public int Front() {
        if(usedSize != 0) {
            return elem[front%elem.length];
        }
        return -1;
    }

    public int Rear() {
        if(usedSize != 0) {
            return elem[(rear - 1 + elem.length) % elem.length];
        }
        return -1;
    }

    public boolean isEmpty() {
        if(usedSize == 0) {
            return true;
        }
        return false;
    }

    public boolean isFull() {
        if(usedSize == elem.length) {
            return true;
        }
        return false;
    }
}*/


//法一自己写
/*class MyCircularQueue {

    private int[] elem;
    int front = 0;
    int rear = 0;
    int usedSize = 0;
    public MyCircularQueue(int k) {
        elem = new int[k];
    }

    public boolean enQueue(int value) {
        if(usedSize != elem.length) {
            elem[rear%elem.length] = value;
            rear++;
            usedSize++;
            return true;
        }
        return false;
    }

    public boolean deQueue() {
        if(usedSize != 0) {
            front++;
            usedSize--;
            return true;
        }
        return false;
    }

    public int Front() {
        if(usedSize != 0) {
            return elem[front%elem.length];
        }
        return -1;
    }

    public int Rear() {
        if(usedSize != 0) {
            return elem[(rear-1)%elem.length];
        }
        return -1;
    }

    public boolean isEmpty() {
        if(usedSize == 0) {
            return true;
        }
        return false;
    }

    public boolean isFull() {
        if(usedSize == elem.length) {
            return true;
        }
        return false;
    }
}*/


//法二：浪费一个元素

/*class MyCircularQueue {

    private int[] elem;
    public int front;
    public int rear;
    public MyCircularQueue(int k) {
        elem = new int[k+1];
    }

    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        this.elem[rear] = value;
        //为了避免下次越界
        rear = (rear+1)%elem.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        front = (front+1)%elem.length;
        return true;
    }

    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return elem[front];
    }

    public int Rear() {
        if(isEmpty()) {
            return -1;
        }
        //考虑到特别情况（当 rear == 0 时 会越界）
        int index = (rear == 0) ? elem.length-1 : rear-1;
        return elem[index];
    }

    public boolean isEmpty() {
        return rear == front;
    }

    public boolean isFull() {
        if((rear+1)%elem.length == front) {
            return true;
        }
        return false;
    }
}*/




